<template>
  <view 
    v-if="visible" 
    class="custom-menu-container"
    @click="handleMaskClick"
  >
    <!-- 遮罩层 -->
    <view class="menu-mask"></view>
    
    <!-- 菜单内容 -->
    <view 
      class="menu" 
      :style="menuPosition"
      @click.stop=""
      @touchstart.stop=""
      @touchmove.stop=""
      @touchend.stop=""
      id="context-menu"
    >
      <view class="menu-content">
        <view class="menu-item" @click.stop="$emit('select', 'feed')">
          <text class="menu-icon">🍎</text>
          <text class="menu-text">喂食</text>
        </view>
        <view class="menu-item" @click.stop="$emit('select', 'play')">
          <text class="menu-icon">🎾</text>
          <text class="menu-text">玩耍</text>
        </view>
        <view class="menu-item" @click.stop="$emit('select', 'rest')">
          <text class="menu-icon">😴</text>
          <text class="menu-text">睡觉</text>
        </view>
        <view class="menu-item" @click.stop="$emit('select', 'info')">
          <text class="menu-icon">ℹ️</text>
          <text class="menu-text">查看信息</text>
        </view>
        <view class="menu-item" @click.stop="$emit('select', 'voice')">
          <text class="menu-icon">{{ isListening ? '🎤' : '🎙️' }}</text>
          <text class="menu-text">{{ isListening ? '停止识别' : '语音识别' }}</text>
        </view>
        <view class="menu-item" @click.stop="$emit('select', 'settings')">
          <text class="menu-icon">⚙️</text>
          <text class="menu-text">设置</text>
        </view>
        <view class="menu-item close-item" @click.stop="$emit('select', 'close')">
          <text class="menu-icon">❌</text>
          <text class="menu-text">关闭宠物</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'PetCustomMenu',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    menuPosition: {
      type: Object,
      default: () => ({})
    },
    isListening: {
      type: Boolean,
      default: false
    }
  },
  emits: ['select', 'close'],
  methods: {
    handleMaskClick() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
/* 自定义菜单容器（移动端） */
.custom-menu-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999999;
  pointer-events: auto;
}

/* 遮罩层 */
.menu-mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  pointer-events: auto;
}

/* 自定义菜单（移动端） */
.menu {
  position: absolute;
  z-index: 1000000;
  background: white;
  border-radius: 20rpx;
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.25);
  border: 3rpx solid #e0e0e0;
  overflow: hidden;
  animation: menuSlideIn 0.3s ease-out;
  min-width: 280rpx;
  pointer-events: auto;
}

.menu-content {
  padding: 12rpx;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 24rpx 28rpx;
  border-radius: 14rpx;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 80rpx;
}

.menu-item:hover {
  background-color: #f5f5f5;
}

.menu-item:active {
  background-color: #e8e8e8;
  transform: scale(0.96);
}

.menu-icon {
  font-size: 44rpx;
  margin-right: 20rpx;
  width: 50rpx;
  text-align: center;
  flex-shrink: 0;
}

.menu-text {
  font-size: 30rpx;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
}

.close-item {
  border-top: 2rpx solid #e0e0e0;
  margin-top: 8rpx;
  padding-top: 24rpx;
}

.close-item .menu-text {
  color: #f44336;
}

@keyframes menuSlideIn {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(-20rpx);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* 响应式调整 */
@media screen and (max-width: 750rpx) {
  .menu {
    border-radius: 16rpx;
    min-width: 320rpx;
  }
  
  .menu-item {
    padding: 28rpx 32rpx;
    min-height: 90rpx;
  }
  
  .menu-icon {
    font-size: 48rpx;
    margin-right: 24rpx;
    width: 56rpx;
  }
  
  .menu-text {
    font-size: 32rpx;
  }
}
</style>
